package cn.jbit.controller;

import cn.jbit.domain.Message;
import cn.jbit.entity.Department;
import cn.jbit.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author 财龙
 * @Description:
 * @date 2020/9/30 11:03
 */
@Controller
@RequestMapping("department")
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;
    @ResponseBody
    @GetMapping("getDepartmentList")
    public Message getDepartmentList(){
        //调用service里面的实现方法
        List<Department> list = this.departmentService.getDepartmentService();
        /*判断是否拿到数据，没拿到的话就给前端反馈失败*/
        if (CollectionUtils.isEmpty(list)){
            return Message.fail();
        }
        return Message.success().add("list",list);
    }
}
